package com.imchen;

import com.imchen.model.EncodeType;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

public class DynamicProguard {



    private final static int start = Integer.parseInt("AB00",16);
    private final static int end = Integer.parseInt("AB5F",16);
    private static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-hh_mm_ss");

    public static void main(String[] args) {
        genUnicode();
    }

    public static String genUnicode() {
        StringBuilder builder=new StringBuilder();
//        List<String> unicodeList=new ArrayList<>();
        Set<String> unicodeSet=new HashSet<>();
        while (true){
            int nameSize=getRandom(1,5);
            StringBuilder builder1=new StringBuilder();
            for (int i = 0; i < nameSize; i++) {
                int unicode=getRandom(start,end);
                builder.append((char) unicode);
                builder1.append((char) unicode);
            }
//            unicodeList.add(builder1.toString());
            unicodeSet.add(builder1.toString());
            builder.append("\n");
            if (unicodeSet.size()>(end-start)){
                break;
            }
        }
//        Collections.sort(unicodeList);
        Iterator iterator=unicodeSet.iterator();
        for (String value:unicodeSet){
            System.out.println(iterator.next());
        }
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
        writeContent(builder.toString(),System.getProperty("user.home")+"/ProGuard/Dictionary");
//        System.out.println(builder.toString());
        return "";
    }

    public static int getRandom(int min,int max){
        final Random random = new Random();
        int s = random.nextInt(max)%(max-min+1) + min;
        return s;
    }

    public static void writeContent(String content,String savePath){
        File file=new File(savePath,"dictionary-gen-"+sdf.format(new Date())+".txt");
        File parentDir=new File(file.getParent());
        if (!parentDir.exists()){
            parentDir.mkdirs();
        }
        try {
            FileOutputStream fos=new FileOutputStream(file);
            fos.write(content.getBytes("UTF-8"));
            fos.flush();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void initUnicodeTable(){
        EncodeType c0=new EncodeType(0,127,null);

        EncodeType c1=new EncodeType(128,255,null);

        EncodeType latinA=new EncodeType(256,383,null);

        EncodeType latinB=new EncodeType(384,591,null);

        EncodeType ipa=new EncodeType(592,687,null);

        EncodeType space=new EncodeType(688,767,null);

        EncodeType cdm=new EncodeType(768,897,null);

        EncodeType gac=new EncodeType(880,1023,"Greek and Coptic");

        EncodeType cyrillic=new EncodeType(1024,1279,null);
        EncodeType cyrillicSup=new EncodeType(1280,1327,null);
        EncodeType armenian=new EncodeType(1328,1423,null);
        EncodeType hebrew=new EncodeType(1424,1535,null);
        EncodeType arabic=new EncodeType(1536,1791,null);
        EncodeType syriac=new EncodeType(1792,1871,null);
        EncodeType arabicSup=new EncodeType(1872,1919,null);
        EncodeType thaana=new EncodeType(1920,1983,null);
        EncodeType nko=new EncodeType(1984,2047,null);
        EncodeType anp=new EncodeType(2048,2143,null);
        EncodeType mandaic=new EncodeType(2144,2175,null);
        EncodeType samaritan=new EncodeType(2176,2223,null);
        EncodeType Devanagari=new EncodeType(2304,2431,null);
        EncodeType Bengali=new EncodeType(2432,2559,null);
        EncodeType Gurmukhi=new EncodeType(2560,2687,"Gurmukhi");
        EncodeType Gujarati=new EncodeType(2688,2815,"Gujarati");
        EncodeType Oriya=new EncodeType(2816,2943,"Oriya");
        EncodeType Tamil=new EncodeType(2944,3071,"Tamil");
        EncodeType Telugu=new EncodeType(3072,3199,"Telugu");
        EncodeType Kannada=new EncodeType(3200,3327,"Kannada");
        EncodeType Malayalam=new EncodeType(3328,3455,"Malayalam");
        EncodeType Sinhala=new EncodeType(3456,3583,"Sinhala");
        EncodeType Thai=new EncodeType(3584,3711,"Thai");
        EncodeType Lao=new EncodeType(3712,3839,"Lao");
        EncodeType Tibetan=new EncodeType(3840,4095,"Tibetan");
        EncodeType Myanmar=new EncodeType(4096,4255,"Myanmar");
        EncodeType Georgian=new EncodeType(4256,4351,"Georgian");
        EncodeType HangulJamo=new EncodeType(4352,4607,"Hangul Jamo");
        EncodeType Ethiopic=new EncodeType(4608,4991,"Ethiopic");
        EncodeType EthiopicSupplement=new EncodeType(4992,5023,"Ethiopic Supplement");
        EncodeType Cherokee=new EncodeType(5024,5119,"Cherokee");
        EncodeType UnifiedCanadianAboriginalSyllabics=new EncodeType(5120,5759,"Unified Canadian Aboriginal Syllabics");
        EncodeType Ogham=new EncodeType(5760,5791,"Ogham");
        EncodeType Tagalog=new EncodeType(5888,5919,"Tagalog");
        EncodeType Hanunóo=new EncodeType(5920,5951,"Hanunóo");
        EncodeType Buhid=new EncodeType(5952,5983,"Buhid");
        EncodeType Tagbanwa=new EncodeType(5984,6015,"Tagbanwa");
        EncodeType Khmer=new EncodeType(6016,6143,"Khmer");
        EncodeType Mongolian=new EncodeType(6144,6319,"Mongolian");
        EncodeType Cham=new EncodeType(6320,6399,"Cham");
        EncodeType Limbu=new EncodeType(6400,6479,"Limbu");
        EncodeType TaiLe=new EncodeType(6480,6527,"Tai Le");
        EncodeType NewTaiLue=new EncodeType(6528,6623,"New Tai Lue");
        EncodeType KmerSymbols=new EncodeType(6624,6655,"Kmer Symbols");
        EncodeType Buginese=new EncodeType(6656,6687,"Buginese");
        EncodeType Batak=new EncodeType(6688,6751,"Batak");
        EncodeType Javanese=new EncodeType(43264,43391,"Javanese");
        EncodeType VitThái=new EncodeType(43776,43871,"Vi?t Thái");
        EncodeType Hiragana=new EncodeType(12352,12447,"Hiragana");
        EncodeType Katakana=new EncodeType(12448,12543,"Katakana");
        EncodeType Bopomofo=new EncodeType(12544,12591,"Bopomofo");
        EncodeType KangxiRadicals=new EncodeType(12032,12255,"Kangxi Radicals");
        EncodeType Coptic=new EncodeType(11392,11519,"Coptic");
        EncodeType LetterlikeSymbols=new EncodeType(8448,8527,"Letterlike Symbols");

    }

}
